home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Add-Ons / MicroPhone / Open Mike™ / Open Mike™ 002 / Mike's Folder / DP Tutorial Pt.2 < prev    next >
Encoding:
Text File  |  1993-02-01  |  7.6 KB  |  133 lines  |  [TEXT/ttxt]

  1. DP Tutorial Pt.2
  2. ================
  3. Copyright © 1993 by Celestin Company
  4. All rights reserved.
  5.  
  6. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without permission in writing from the publisher. However, you are permitted to make copies of this work, printed or otherwise, as long as said copies are for your personal use only.
  7.  
  8. Introduction
  9. ------------
  10. Last time, we designed a profile dialog and was able to extract information from it. This time, we'll take the profile dialog one step further by introducing a "hit handler". Hit handlers allow you to interact directly with the dialog. You can do things like check all the edit text fields for a value before dismissing the dialog. We will also make some additions to our Profile dialog, including a popup menu.
  11.  
  12. Design
  13. ------
  14. This tutorial assumes that you know the basics of how to use ResEdit. If you don't, refer to DP Tutorial Pt.1, or to the ResEdit reference manual.
  15.  
  16. 1. Create a new MicroPhone settings document called "DP Test2".
  17.  
  18. 2. Open this settings document with ResEdit and create a new DLOG called "Profile" with the ID 7777. Create a corresponding DITL of the same ID.
  19.  
  20. 3. Create the following dialog items:
  21.  
  22.   1 - "OK" button
  23.   2 - "Cancel" button
  24.   3 - "Other" button
  25.   4 - "Name" edit field
  26.   5 - "Password" edit field
  27.   6 - "Phone" edit field
  28.   7 - "# of Tries" useritem
  29.   8 - "Name" static field
  30.   9 - "Password" static field
  31.   10 - "Phone" static field
  32.   11 - "# of Tries" static field
  33.  
  34. This dialog exists already in the DP Tutorial Pt.2 settings document, so you don't really need to create it. Take a look at the dialog using ResEdit to get a feel for how the dialog has been designed.
  35.  
  36. A Simple Example
  37. ----------------
  38. To recap what was discussed in the previous tutorial, here is a simple example of how to interact with a dialog. This script, places defaults values into the dialog, displays the dialog, and checks if the OK button has been hit. The script is called "Dialog1" in the DP Tutorial Pt.2 settings document.
  39.  
  40. Remark "--- Dialog1 ---"
  41. Remark "--- puts default values into dialog items and"
  42. Remark "--- displays the dialog named Profile"
  43. Remark "--- and returns new values of the OK button is clicked"
  44. Remark "---"
  45. Remark "--- configure the default values"
  46. Set Variable * tries from Expression "'1^M2^M3^M4^M5'"
  47. Set Variable * theName from Expression "'Penny Copper'"
  48. Set Variable * thePassword from Expression "'nickel'"
  49. Set Variable * thePhone from Expression "'555-1212'"
  50. Set Variable * theTries from Expression "'3'"
  51. Remark "--- display the dialog"
  52. Set Variable * d0 from Expression "'Profile'"
  53. Set Variable * d4 from Expression "'4◊' & theName"
  54. Set Variable * d5 from Expression "'5◊' & thePassword"
  55. Set Variable * d6 from Expression "'6◊' & thePhone"
  56. Set Variable * d7 from Expression "'7◊userPop ' & theTries & '^M' & tries"
  57. Set Variable * dResult from Expression "MPDialogerPro(d0,d4,d5,d6,d7)"
  58. If Expression "ItemFetch(dResult,'^M',1) = 'OK'"
  59.   Alert * OK "'The OK button was clicked.'"
  60. End If
  61.  
  62. All of the values in the dialog are stored in the variable called dResult, in a carriage return delimited list. The first item of the dialog is the OK button. MPDialogerPro will return the name of the button that is clicked, which is why we look for 'OK'. If the Cancel button had been clicked, the second value in dResult's carriage return delimited list would have been 'Cancel', and the first item would have been blank.
  63.  
  64. Hit Handlers
  65. ------------
  66. A hit handler allows you to do things to a dialog without causing the dialog to be dismissed in the process. For example, there is a button called "Other" in our example dialog. If you ran the above script and clicked on that button, nothing would happen. Clicking on "Other" won't even dismiss the dialog, since as a default, only items 1 and 2 in a dialog will dismiss the dialog.
  67.  
  68. To include a hit handler with a dialog, put the word 'on' and the name of the hit handler along with the name of the dialog, with a carriage return between, like this:
  69.  
  70. Set Variable * d0 from Expression "'Profile^Mon Profile_handler'"
  71.  
  72. Whenever anything happens that causes a hit in the dialog, the script "Profile_handler" will be executed and a variable called "dialog" will be generated, pointing to the dialog that received the hit. Hits can be caused by clicking items, moving the dialog, or even putting the dialog in the background or bringing it to the foreground.
  73.  
  74. Here, we modify our script and introduce the hit handler:
  75.  
  76. Remark "--- Dialog2 ---"
  77. Remark "--- puts default values into dialog items and"
  78. Remark "--- displays the dialog named Profile"
  79. Remark "--- and uses a hit handler called Profile_handler"
  80. Remark "---"
  81. Remark "--- configure the default values"
  82. Set Variable * tries from Expression "'1^M2^M3^M4^M5'"
  83. Set Variable * theName from Expression "'Penny Copper'"
  84. Set Variable * thePassword from Expression "'nickel'"
  85. Set Variable * thePhone from Expression "'555-1212'"
  86. Set Variable * theTries from Expression "'3'"
  87. Remark "--- display the dialog"
  88. Set Variable * d0 from Expression "'Profile^Mon Profile_handler'"
  89. Set Variable * d4 from Expression "'4◊' & theName"
  90. Set Variable * d5 from Expression "'5◊' & thePassword"
  91. Set Variable * d6 from Expression "'6◊' & thePhone"
  92. Set Variable * d7 from Expression "'7◊userPop ' & theTries & '^M' & tries"
  93. Set Variable * dResult from Expression "MPDialogerPro(d0,d4,d5,d6,d7)"
  94.  
  95. Note that the last thing we do now in the script is called MPDialogerPro. Everything else will be handled by the hit handler assigned to the dialog. And here's the hit handler:
  96.  
  97. Remark "--- Profile_handler ---"
  98. Remark "--- hit handler for Profile dialog"
  99. If Expression "itemHit = '0'"
  100.   Remark "--- this is an opportunity to initialize the dialog"
  101.   Remark "--- before it is actually displayed"
  102.   Remark "--- but, we don't need to do anything for this example"
  103. Else If Expression "itemHit = '1'"
  104.   Remark "--- the OK button was clicked"
  105.   Alert * OK "'You clicked OK.'"
  106. Else If Expression "itemHit = '2'"
  107.   Remark "--- the Cancel button was clicked"
  108.   Alert * OK "'You clicked Cancel.'"
  109. Else If Expression "itemHit = '3'"
  110.   Remark "--- the Other button was clicked"
  111.   Alert * OK "'You clicked the Other button'"
  112. End If
  113.  
  114. Other Examples
  115. --------------
  116. There are several other examples in the DP Tutorial Pt.2 settings document. They demonstrate ways in which the hit handler can fine-tune the way the dialog is handled.
  117.  
  118. Dialog3 - demonstrates the ability to change the behavior of a button. In this example, the OK button no longer dismisses the dialog, but the Other button does. This is accomplished by the following lines in the script:
  119.  
  120. Do XCMD * MPChangerPro "dialog,'1◊NoDismiss'"
  121. Do XCMD * MPChangerPro "dialog,'3◊Dismiss'"
  122.  
  123. MPChangerPro is an XCMD that works in conjunction with MPDialogerPro, allowing you to change the contents of a dialog on the fly. Note that "dialog" is a variable that always points to the dialog that received the hit. The syntax for MPChangerPro is:
  124.  
  125. dialog,'item◊command'
  126.  
  127. where dialog is a pointer to the dialog. This value is generated automatically whenever a dialog receives a hit. Item is the number of the item in the dialog. Command is what you want MPChangerPro to do to the item.
  128.  
  129. Dialog4 - demonstrates the ability to make changes to the values in a dialog. In this example, if you click the Other button, it changes the phone number in the edit field to the current time. This is accomplished by the following line in the script:
  130.  
  131. Do XCMD * MPChangerPro "dialog,'6◊' & String(Hour) & String(Minute)"
  132.  
  133. You are telling MPChangerPro to pass the current hour and minute to item number six in the dialog.